<%@ page language="java" import="java.util.*, com.zjut.zs.user.manager.*, com.zjut.zs.user.dao.*, com.zjut.an.util.tools.*,com.zjut.an.util.system.*" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="renderer" content="webkit" />
    <title><%=Config.webname%></title>
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<%
ZsUserManager manager = (ZsUserManager) SpringContextUtil.getBean("ZsUserManager");
MD5 md5 = (MD5) SpringContextUtil.getBean("MD5");
Integer usId = Integer.parseInt(request.getParameter("usId"));
String code = request.getParameter("code");
ZsUser obj = manager.getData(usId);
if (obj ==null || !md5.toMD5(String.valueOf(obj.getLoginTime())).equals(code)) {
	response.sendRedirect("message.jsp?message=链接已经失效");
} 
 %>
 
 <div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="index.jsp">首页</a></li>
    <li><a href="#">密码重置</a></li>
    </ul>
    </div>
    
    <form id="ff" name="add" role="form" class="form-horizontal" action="" method="post">  
	    <div class="formbody">    
	    <div class="formtitle"><span>账号注册</span></div>    
	    <ul class="forminfo">
	    <li><label>密码<b>*</b></label><input id="usPassword" name="usPassword" type="password" class="dfinput" placeholder="新密码" required minlength="6" maxlength="20" data-msg-minlength="请输入最小6位" /><i>6-20位，包含字母和数字</i></li>
	    <li><label>确认密码<b>*</b></label><input id="usPassword2" name="usPassword2" type="password" class="dfinput" placeholder="确认新密码" required equalTo="#usPassword"/></li>
	    
	    <li><label>&nbsp;</label><button type="submit" class="btn btn-primary btn-sm">重置 </button>
	    <input class="form-control" name="usId" type="text" id="usId" value="<%=obj.getUsId() %>" style="display:none"/> 
	    </li>
	    
	    </ul>    
	    </div>
    </form>
 

<script src="../plugins/assets/plugins/jquery-3.5.1.min.js" type="text/javascript"></script> 
<script src="../plugins/assets/plugins/jquery-validation-1.14.0/dist/jquery.validate.js" type="text/javascript"></script>
<script src="../plugins/assets/plugins/jquery-validation-1.14.0/dist/jquery.metadata.js" type="text/javascript"></script>
<script src="js/formvalidate.js" type="text/javascript"></script>
<script src="../admin/js/publicManager.js" type="text/javascript" charset="utf-8"></script> 
</body>
	<script type="text/javascript">  
	$(function(){
	    //jquery.validate
		$("#ff").validate({
			submitHandler: function() {
					//验证通过后 的js代码写在这里
					submitForm();
			}
		})
	})
	
		function submitForm() {
			var jsonString = JSON.stringify(serializeToJSON('#ff'));
			//console.log(jsonString);
			ajaxSubmitForm(jsonString);
		}

		function serializeToJSON(formname) {
			var serializeObj=serializeForm($(formname));  
			//console.info(serializeObj);
		    return serializeObj;   
		}

		function serializeForm(form) { /* 将form表单内的元素序列化为对象，扩展Jquery的一个方法 */
			var o = {};
			$.each(form.serializeArray(), function(index) {
				if (o[this['name']]) {
					o[this['name']] = o[this['name']] + "," + this['value'];
				} else {
					o[this['name']] = this['value'];
				}
			});
			return o;
		}
		
		function ajaxSubmitForm(jsonString) {
			//console.log(jsonString);
			$.ajax({
		    	cache: false,
		    	type: "POST",
		        url:"../resetPassword.action",
		        data:{rowstr:jsonString},// 你的formid
		        async: false,
		        error: function(request) {
		        	alert("网络有误");
		        },
		        success: function(data) {
		        	//console.log(data);
		        	if(data.message=="success"){
		            	alert("修改成功！");
		            	window.location = 'main.jsp';
		        	} else {
		        		alert("修改失败！");
		        		window.location = 'getpassword1.jsp';
		        	}
		        }
		    });
		}
		
		
	</script>
</html>